home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutord.EXE
/
FILEORG
< prev
next >
Wrap
Text File
|
1993-04-30
|
2KB
|
90 lines
File organization example:
/* section 1 */
#include <stdio.h>
/* section 2 */
/*
* This is an example of organizing a source file for use in a
* make believe project called operation codify.
*
* Operation codify is used to organize a source file in a predictable
* format which can be used by all programmers working on the same
* project.
*
*/
/* section 3 */
#define ON 1
#define OFF 0
/*
* node definition of the binary tree.
*
*/
struct tree {
struct tree *right;/* pointer to right subtree */
struct tree *left; /* pointer to left subtree */
int data; /* numerical data to be stored in tree */
};
/* Function prototype - "buildtree": used to build the binary tree */
int buildtree( struct tree * );
/* section 4 */
/* section 5 */
main()
{
int err; /* error flag, 0=ok, -1=error */
struct tree root; /* define the root node of the tree */
err=buildtree(&root);
/* check error condition, exit if problem */
if( err == -1 ){
printf("Buildtree could not allocate memory!\n");
/* return to op system */
exit();
}
/* ... */
}
/*
* buildtree
*
* Purpose: buildtree is responsible for building a binary tree
* which will be used to numerically sort a list of
* numbers. The list of numbers is stored in the tree
* one number at a time using the following algorithm:
*
* if( number < node value )
* go left
* else
* go right
*
* buildtree is called recursively when a value is found
* at the current node. When a value is not found, a new
* node is malloc'ed and initialized. buildtree is then
* called again with the address of the new node.
*
* Inputs:
* struct node * (pointer to a node structure)
*
* Outputs:
* int (error condition flag), possible values:
*
* 0 - all is well
* -1 - could not allocate memory correctly
*
*
* Linage:
* John Doe 01/01/77 1.0 Original version
*
* (all mods will be identified here, along with their
* creator and the date.)
*
*/
int buildtree( struct tree *node )
{
/* ... */
}